Conda¶
miniconda is a light version of anaconda,
it contains only Conda, Python and other necessary tools.
miniforge is similar to minicoda
but conda-forge is the only channel by default.
miniconda has package installer while
miniforge has only command installer.
Use conda-forge channel instead of defaults channel when installing packages
and use pip only when conda doesn't have certain packages.
Install conda¶
First, download miniconda package installer and install it.
Second, configure conda in file .zshrc
(a place for personal configurations):
- Open
.zshrcin terminalvim ~/.zshrc, - Type
ito open edit mode (--INSERT-- will appear at bottom), - Write
export PATH=/path/to/miniconda3/bin:$PATHin a new line, - Press
escto close edit mode, - Move the cursor to end and type
:(:will appear at bottom), typewq(add!if there is read only problem) after:and pressenterto close.zshrc, - Make configurations effective
source ~/.zshrc.
Third, set conda-forge as the only channel:
- Add
conda-forgechannelconda config --add channels conda-forge, - Remove
defaultschannelconda config --remove channels defaults, - Update all packages in
baseenvironment withconda-forgechannelconda update --all.
If using Mac and xcrun error occurs, use xcode-select --install.
Conda commands¶
conda --version
conda list
conda search --full-name pkg_precise
conda search pkg_pattern
conda install pkg=version
conda uninstall pkg
conda update conda
conda update pkg=version
conda update --all
conda create --name env python=version
conda create --name env1 --clone env2
conda activate env
conda deactivate
conda env list
conda env remove --name env
conda config --get channels
conda config --add channels channel
conda config --set channel_priority strict
conda config --remove channels channel
Pip¶
Install pip¶
pip comes with conda environments.
To solve spuare brackets no matches found issue when using pip:
- Open
.zshrcin terminalvim ~/.zshrc, - Type
ito open edit mode (--INSERT-- will appear at bottom), - Write
setopt no_nomatchin a new line, - Press
escto close edit mode, - Move the cursor to end and type
:(:will appear at bottom), typewq(add!if there is readonly problem) after:and pressenterto close.zshrc, - Make configurations effective
source ~/.zshrc.
Pip commands¶
pip --version
pip list
pip list --outdated
pip check pkg
pip check
pip install pkg==version
pip install --upgrade pip
pip install --upgrade pkg==version
pip uninstall pkg
pip freeze
pip freeze > requirements.txt
pip install -r requirements.txt
Environments¶
Using Jupyter notebook in VSCode doesn't require official Jupyter installed but these packages are needed:
ipykernelconverts conda environments into kernels- nbconvert and pretty-jupyter export Jupyter notebooks into htmls
Create data environment in base environment:
conda create --name data ipykernel \
python python-docx pandas openpyxl ydata-profiling \
scikit-learn py-xgboost lightgbm catboost optuna \
langchain openai transformers \
plotly nbconvert
pip install pretty-jupyter
To activate data environment and enter into Projects directory
when launching terminal:
- Open
.zshrcin terminalvim ~/.zshrc, - Type
ito open edit mode (--INSERT-- will appear at bottom), - Write
conda activate dataandcd /path/to/Projectsin separated new lines, - Press
escto close edit mode, - Move the cursor to end and type
:(:will appear at bottom), typewq(add!if there is readonly problem) after:and pressenterto close.zshrc, - Make configurations effective
source ~/.zshrc.
Git¶
Use SSH rather than https
for fast and stable connection from local to remote.
Set up SSH (step 1):¶
- Launch terminal and go to
homedirectorycd ~, - Generate an SSH key pair
ssh-keygen -t ed25519 -C "user-email", - Press
enterto confirm default directory path, - Choose your
passphrase.
Set up Gitee:¶
- Run
cat ~/.ssh/id_ed25519.pub, use the contents as new SSH key on Gitee and usestudioas SSH key title, - Authenticate SSH for Git
git config --global user.name "gitee-user-name"andgit config --global user.email "gitee-user-email", - Go to
Projectsdirectorycd /path/to/Projects/, clone Gitee repository to localgit clone git@gitee.com:gitee-user-name/repository, enteryesto confirm connection and enter yourpassphraseto continue, - Test SSH connection from local to Gitee
ssh -T git@gitee.com.
Set up GitHub:¶
- Run
cat ~/.ssh/id_ed25519.pub, use the contents as new SSH key on GitHub and usestudioas SSH key title, - Authenticate SSH for Git
git config --global user.name "github-user-name"andgit config --global user.email "github-user-email", - Go to
Projectsdirectorycd /path/to/Projects/, clone GitHub repository to localgit clone git@github.com:github-user-name/repository, enteryesto confirm connection and enter yourpassphraseto continue, - Test SSH connection from local to GitHub
ssh -T git@github.com.
Set up SSH (step 2):¶
- Ensure correct SSH key file permissions
chmod 600 ~/.ssh/id_ed25519.pub, - Add SSH key to SSH agent
ssh-add ~/.ssh/id_ed25519.